import Vue from 'vue'
import Router from 'vue-router'
import Homepage from '@/pages/Homepage/Main'
import Category from '@/pages/Goods/Category'
import Cart from '@/pages/Cart/Main'
import Usercenter from '@/pages/Usercenter/Main'
import Collection from '@/pages/Usercenter/Collection'
import Share from '@/pages/Usercenter/Share'
import HomepageContainer from '@/pages/HomepageContainer'
import CommonContainer from '@/pages/CommonContainer'
import DrawMoney from '@/pages/Revenue/DrawMoney'
import RevenueDetail from '@/pages/Revenue/RevenueDetail'
import RevenueMonthly from '@/pages/Revenue/RevenueMonthly'
import RevenueRule from '@/pages/Revenue/Rule'
import Pay from '@/pages/Homepage/Pay'
import Goods from '@/pages/Goods/Detail'
import GoodsComment from '@/pages/Goods/Comment'
import GoodsList from '@/pages/Goods/GoodsList'
import Search from '@/pages/Goods/Search'
import Members from '@/pages/Member/Members'
import OrderList from '@/pages/Order/OrderList'
import OrderDetail from '@/pages/Order/OrderDetail'
import CreateOrder from '@/pages/Order/CreateOrder'
import BuyMembership from '@/pages/Order/BuyMembership'
import PaySuccess from '@/pages/Order/PaySuccess'
import WriteComment from '@/pages/Order/WriteComment'
import Refund from '@/pages/Order/Refund'
import AddressList from '@/pages/Address/AddressList'
import AddressEdit from '@/pages/Address/AddressEdit'

Vue.use(Router)

const route = new Router({
  routes: [
    {
      path: '/',
      component: HomepageContainer,
      children:[{
        path:'',
        name:'homepage',
        component: Homepage,
        meta: {title: '首页'}
      },{
        name:'category',
        path:'category',
        component: Category,
        meta: {title: '分类'}
      },{
        name:'cart',
        path:'cart',
        component: Cart,
        meta: {title: '购物车'}
      },{
        name:'usercenter',
        path:'usercenter',
        component: Usercenter,
        meta: {title: '个人中心'}
      }]
    },{
      path:'/goods',
      component: CommonContainer,
      children:[{
        path: 'detail/:preGoodsId',
        name: 'Goods',
        component: Goods,
        meta: {title: '商品详情'}      
      },{
        path: 'comment/:preGoodsId',
        name: 'goodsComment',
        component: GoodsComment,
        meta: {title: '商品评论'}      
      },{
        name: 'goodsList',
        path: 'list/:classId',
        component: GoodsList,
        meta: {title: '商品列表'}      
      },{
        name: 'search',
        path: 'search',
        component: Search,
        meta: {title: '搜索'}
      }]
    },{
      path:'/user',
      name: 'User',
      component: CommonContainer,
      children:[{
        name: 'drawMoney',
        path:'drawMoney',
        component: DrawMoney,
        meta: {title: '账户余额'}
      },{
        name: 'revenueDetail',
        path: 'revenueDetail',
        component: RevenueDetail,
        meta: {title: '收益明细'}
      },{
        name: 'revenueMonthly',
        path: 'revenueMonthly',
        component: RevenueMonthly,
        meta: {title: '月收益记录'}
      },{
        name: 'share',
        path: 'share/:userId',
        component: Share,
        meta: {title: '分享二维码'}
      },{
        name: 'share',
        path: 'share',
        component: Share,
        meta: {title: '分享二维码'}
      },{
        name: 'rule',
        path: 'rule',
        component: RevenueRule,
        meta: {title: '会员收益'}
      },{
        name: 'member',
        path: 'member',
        component: Members,
        meta: {title: '会员管理'}
      },{
        name: 'collection',
        path: 'collection',
        component: Collection,
        meta: {title: '我的收藏'}
      }]
    },{
      path: '/order',
      component: CommonContainer,
      children:[{
        path:'list',
        name:'orderList',
        component: OrderList,
        meta: {title: '我的订单'}
      },{
        path:'detail/:orderId',
        name:'orderDetail',
        component: OrderDetail,
        meta: {title: '订单详情'}
      },{
        path:'writeComment/:orderId/:goodsId',
        name:'orderComment',
        component: WriteComment,
        meta: {title: '评价订单'}
      },{
        path:'refund/:orderId/:goodsId',
        name:'orderRefund',
        component: Refund,
        meta: {title: '申请退换货'}
      },{
        path: 'pay',
        name: 'createOrder',
        component: CreateOrder,
        meta: {title: '创建订单'}
      },{
        name: 'buyMembership',
        path: 'buyMembership',
        component: BuyMembership,
        meta: {title: '升级创享会员'}
      },{
        path:'paySuccess/:id',
        name:'paySuccess',
        component: PaySuccess,
        meta: {title: '付款成功'}
      }]
    },{
      path:'/address',
      component: CommonContainer,
      children:[{
        path:'',
        name:'addressList',
        component: AddressList,
        meta: {title: '地址列表'}
      },{
        path:'edit/:addressId',
        name:'addressEdit',
        component: AddressEdit,
        meta: {title: '地址编辑'}
      }]
    }
  ],
  mode: 'history',
  base: '/shopping_zhou/php/WX_web/Idaxue/'
})

route.afterEach(route => {
  document.title = route.meta.title;
  console.log('router change to:', route)
})

export default route;
